package com.yociyy.admin.controller;

import cn.hutool.core.util.StrUtil;
import com.github.pagehelper.PageHelper;
import com.yociyy.admin.biz.BaseLogBiz;
import com.yociyy.admin.model.entity.BaseLog;
import com.yociyy.common.core.msg.R;
import com.yociyy.common.core.msg.TableR;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * 系统管理-日志管理
 * 
 * @author Y.yang
 * @date 2020/5/20
 */
@RestController
@RequestMapping("log")
public class BaseLogController {

	@Autowired
	private BaseLogBiz baseLogBiz;

    /**
     * 查询日志信息分页列表
     */
	@GetMapping("/page")
	public TableR page(@RequestParam Map<String, Object> params) {
		PageHelper.startPage(params);
		return new TableR(baseLogBiz.selectPage(params));
	}

    /**
     * 查询日志信息通过id
     */
	@GetMapping("/{id}")
	public R getLog(@PathVariable("id") Long id) {
		return R.success(baseLogBiz.selectLogById(id));
	}

	/**
     * 新增日志信息
	 */
	@PostMapping
	public R addLog(@RequestBody BaseLog baseLog) {
		baseLogBiz.insertLog(baseLog);
		return R.success();
	}

    /**
     * 修改日志信息
     */
	@PutMapping
	public R putLog(@RequestBody BaseLog baseLog) {
		baseLogBiz.updateLog(baseLog);
		return R.success();
	}

    /**
     * 删除日志信息
     */
	@DeleteMapping
	public R delLog(@RequestParam String ids) {
        long[] idArray = StrUtil.splitToLong(ids, ",");
        baseLogBiz.deleteLogByIds(idArray);
        return R.success();
	}
}
